<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }

    .work-day {
        /*border: 1px solid red;*/
    }

    .ivu-date-picker-rel {
        width: 200px !important;
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110" style="width: 30%">
        <div class="free-day" style="background:#eee;padding: 10px;margin-bottom: 20px">
            <Card :bordered="false">
                <p slot="title">审核规则设置</p>
                <!--<selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>-->
                <Form-item label="适用人员类型" prop="Forpeopletype">
                    <i-select v-model="formValidate.Forpeopletype" placeholder="请选择适用人员类型">
                        <template v-for="(item,index) in peopleTypeArr">
                            <i-option :value="item.Id">{{item.PeopleTypeTitle}}</i-option>
                        </template>
                    </i-select>
                </Form-item>
                <Form-item label="规则名称" prop="Rolename">
                    <i-input v-model="formValidate.Rolename" placeholder="请填写规则名称"></i-input>
                </Form-item>
                <Form-item label="人员类型" prop="Flow">
                    <i-select placeholder="选择审批人员类型" multiple v-model="flowDetail" filterable
                              @on-change="checkChangeGate">
                        <i-option v-for="item in peopleTypeArr" :value="item.Id">{{ item.PeopleTypeTitle }}
                        </i-option>
                    </i-select>
                </Form-item>
                <Form-item label="生效里程限制" prop="Limitmiles">
                    <div style="display: flex;width: 70px">
                        <i-input v-model="formValidate.Limitmiles" type="number"
                                 placeholder="请输入生效里程限制"></i-input><span style="font-weight: bolder;font-size: 13px">km</span>
                    </div>
                </Form-item>
                <Form-item label="生效小时数限制" prop="Limithours">
                    <div style="display: flex;width: 70px">
                        <i-input v-model="formValidate.Limithours" type="number"
                                 placeholder="几小时"></i-input><span style="font-weight: bolder;font-size: 13px">h</span>
                    </div>
                </Form-item>
                <!--<Form-item label="是否需要上级审核员审核" prop="Isneeduplevelcheck">-->
                    <!--<Checkbox @on-change="checkboxChange2" :value="formValidate.Isneeduplevelcheck"></Checkbox>-->
                <!--</Form-item>-->
                <Form-item label="立即生效" prop="State">
                    <Checkbox @on-change="checkboxChange" :value="formValidate.State"></Checkbox>
                </Form-item>
            </Card>
        </div>
        <!--</div>-->
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="backGoJump()" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>

    import apiUtil from '../../assets/utils/api_util';
    import selectSearch from '../../components/selectSearch';

    /*
    * 车辆审核规则管理
    * 参数 Rolename（规则名称），State（是否立即生效true|false），
    * Limitmiles（生效里程限制，整数），Limithours（生效小时数限制，整数）
    * ，Pointcheckerid（指定的审核员ID，GUID），Isneeduplevelcheck（是否需要上级审核员审核true|false）
    */



    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    State: true,
                    Limitmiles: '',
                    Limithours:'',
                    Forpeopletype:'',
                    // Isneeduplevelcheck:false,
                    Flow:[]
                    // Isneeduplevelcheck:false,
                },
                ruleValidate: {},
                //选择审核人
                selectBaseInfo: {
                    "title": '选择审核人',
                    "placeholder": '请输入姓名',
                    "postUrl": apiUtil.urls.userList,
                    'postType': 'user',
                },
                reqpeopleDept:'',
                flowDetail:[],
                peopleTypeArr:[],
            }
        },
        mounted: function () {
            this.getDetail();
            this.getPeopleTypeData();
        },

        components: {
            selectSearch
        },
        methods: {
            //backJump
            backGoJump: function () {
                this.$router.back(-1)

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.editData(model);
                })
            },
            //获取适用人员类型
            getPeopleTypeData: function () {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GetPeopleTypes, params, function (res) {
                    that.$Loading.finish();
                    that.peopleTypeArr = res.Msg;

                    console.log('res:', res)
                });


            },
            //选择人员类型
            checkChangeGate: function (data) {
                console.log('多选值:', data);
                let arr = Array.from(data);
                this.formValidate.Flow = arr.join();
                console.log('checkChangeGate:', this.formValidate.Flow);
            },
            //是否需要上级审核员审核
            checkboxChange2: function (data) {
                this.formValidate.Isneeduplevelcheck = data;
            },
            //是否立即生效
            checkboxChange: function (data) {
                this.formValidate.State = data;
            },
            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
            },
            //编辑
            editData: function (model) {
                let that = this;
                model.Id = that.$route.query.id;
                // model.Pointcheckerid = this.reqpeopleDept.resultId;
                let params = that.$qs.stringify(model);
                this.$Loading.start();
                console.log('发送数据:', params);

                apiUtil.post(that, apiUtil.urls.EditCarReqCheckRole, params, function (res) {
                    that.$Loading.finish();
                    that.$Notice.open({
                        title: '通知',
                        desc: "修改成功 "
                    });
                });
            },

            //获取详情
            getDetail: function () {
                let that = this;

                let para = {
                    roleId: that.$route.query.id,
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.CarReqCheckRolesDetail, para, function (res) {
                    that.$Loading.finish();
                    that.formValidate.Rolename =res.Msg.Rolename;
                    that.formValidate.State =res.Msg.State;
                    // that.formValidate.Isneeduplevelcheck =res.Msg.Isneeduplevelcheck;
                    // that.formValidate.Isneeduplevelcheck =res.Msg.Isneeduplevelcheck;
                    that.formValidate.Limitmiles =res.Msg.Limitmiles;
                    that.formValidate.Forpeopletype =res.Msg.Forpeopletype;
                    that.formValidate.Limithours =res.Msg.Limithours;
                    that.formValidate.Limithours =res.Msg.Limithours;
                    // that.reqpeopleDept.resultId =res.Msg.Pointcheckerid;

                    res.Msg.Flow.split(',').forEach(function (item,i) {
                        that.flowDetail.push(Number(item))
                    })

                    console.log('flowDetail:,',that.flowDetail)
                });
            }


        }
    }
</script>
